/**
 * Pulley joint definition. This requires two ground anchors,
 * two dynamic body anchor points, and a pulley ratio.
**/
public class b2PulleyJointDef extends b2JointDef {

	public b2PulleyJointDef()
	{
		type = b2JointType.e_pulleyJoint;
		groundAnchorA = new b2Vec2(-1.0f, 1.0f);
		groundAnchorB = new b2Vec2(1.0f, 1.0f);
		localAnchorA = new b2Vec2(-1.0f, 0.0f);
		localAnchorB = new b2Vec2(1.0f, 0.0f);
		lengthA = 0.0f;
		lengthB = 0.0f;
		ratio = 1.0f;
		collideConnected = true;

		mLengthArray = new float[2];
	}

	public void release() {
		groundAnchorA.release();
		groundAnchorB.release();
		localAnchorA.release();
		localAnchorB.release();
	}

	/// Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
	public void Initialize(b2Body bodyA, b2Body bodyB,
					final b2Vec2 groundAnchorA, final b2Vec2 groundAnchorB,
					final b2Vec2 anchorA, final b2Vec2 anchorB,
					float ratio)
	{
		this.bodyA = bodyA;
		this.bodyB = bodyB;

		double value = jni_b2PulleyJointDef_Initialize1(
							this.groundAnchorA.address, this.groundAnchorB.address,
							this.localAnchorA.address, this.localAnchorB.address,
							bodyA.address, bodyB.address,
							groundAnchorA.address, groundAnchorB.address,
							anchorA.address, anchorB.address
						);
		this.ratio = ratio;

		lengthA = (float)(value >> 32);
		lengthB = (float)((value << 32) >> 32);
		
	}
	private static float[] mLengthArray;

	private static native double jni_b2PulleyJointDef_Initialize1(
		int groundA, int groundB, int localA, int localB,
		int bodyA, int bodyB,
		int groundAnchorA, int groundAnchorB,
		int anchorA, int anchorB
	);

	/// The first ground anchor in world coordinates. This point never moves.
	public b2Vec2 groundAnchorA;

	/// The second ground anchor in world coordinates. This point never moves.
	public b2Vec2 groundAnchorB;

	/// The local anchor point relative to bodyA's origin.
	public b2Vec2 localAnchorA;

	/// The local anchor point relative to bodyB's origin.
	public b2Vec2 localAnchorB;

	/// The a reference length for the segment attached to bodyA.
	public float lengthA;

	/// The a reference length for the segment attached to bodyB.
	public float lengthB;

	/// The pulley ratio, used to simulate a block-and-tackle.
	public float ratio;
}
